package com.example.springaop.myAop.staticStateProxy;

import com.example.springaop.myAop.ArithmeticCalculator;
import com.example.springaop.myAop.MyLogger;

/**
 * 代理类
 */
public class ProxyLogger implements ArithmeticCalculator {

    //目标类
    private ArithmeticCalculator target;

    //日志类
    private MyLogger logger;

    public ProxyLogger(ArithmeticCalculator target, MyLogger logger) {
        this.target = target;
        this.logger = logger;
    }
    @Override
    public int add(int i, int j) {
        logger.showParam(i, j);
        int result =  target.add(i,j);
        logger.showResult(result);
        return result;
    }
    @Override
    public int sub(int i, int j) {
        logger.showParam(i, j);
        int result =  target.sub(i,j);
        logger.showResult(result);
        return result;
    }
    @Override
    public int mul(int i, int j) {
        logger.showParam(i, j);
        int result =  target.mul(i,j);
        logger.showResult(result);
        return result;
    }
    @Override
    public int div(int i, int j) {
        logger.showParam(i, j);
        int result =  target.div(i,j);
        logger.showResult(result);
        return result;
    }
}
